package com.winkyle.woodenfish.presenter;

import com.winkyle.woodenfish.controller.fragment.AccountDataFragment;
import com.winkyle.woodenfish.entity.HttpResult;
import com.winkyle.woodenfish.entity.UserInfo;
import com.winkyle.woodenfish.mvpview.AccountDataView;
import com.winkyle.woodenfish.retrofit.UserInfoRetrofit;
import com.winkyle.woodenfish.rx.HttpSubscriber;


/**
 * @author winkyle
 * @date 2018/06/15
 * @description  碎片类 {@link AccountDataFragment}的p层
 */

public class AccountDataPresenter extends BaseMvpPresenter<AccountDataView> {
    /**
     * @description 向服务器请求个人资料信息，若请求成功
     *               则调用v层刷新个人资料方法，若失败则弹出提示框，告知原因
     * @return
     */
    public void viewPersonalData(){
        subscribeToRequest(createRetrofitApi(UserInfoRetrofit.class).findUserInfoByUserId(),
                new HttpSubscriber<AccountDataPresenter,HttpResult<UserInfo>>(this) {
                    @Override
                    public void processData(HttpResult<UserInfo> httpResult) {
                        if(httpResult.getCode() == 1){
                            getMvpView().refreshPersonalData(httpResult.getBody());
                            return;
                        }
                        getMvpView().showShortToast(httpResult.getMsg());
                    }
                });

    }
}
